package cn.quicklydoit.utils;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 常用方法
 */
public final class CommonUtils {

    /**
     * 可选字符
     */
    private static String optionalChar="0123456789abcdefghijklmnopqrstuvwxwzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static boolean isEmpty(String str){
        return "".equals(str) || str==null;
    }

    public static boolean isNotEmpty(String str){
        return !isEmpty(str);
    }


    /**
     * 判断输入是否为正确邮箱
     * @param email
     * @return
     */
    public static boolean isEmail(String email){
        if(isNotEmpty(email)){
            String pattern="^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$";
            Pattern p = Pattern.compile(pattern);
            Matcher m = p.matcher(email);
            if(m.matches()){
                return true;
            }else{
                return false;
            }
        }else
            return  false;
    }

    /**
     * 随机生成
     * @param length
     * @return
     */
    public static String random(int length){
        return random(length,length/2,length-length/2);
    }


    /**
     *
     * @param length
     * @param numLength 数字个数
     * @param enLength 英文字母个数
     * @return
     */
    public static String random(int length,int numLength,int enLength){
        //设置随机数的种子  为了便于测试 先试用固定种子
        long currentTime=System.currentTimeMillis();
        final int randomValue = new Random(10l).nextInt(length+1);

        StringBuilder sb=new StringBuilder();


        //TODO
        for(int i=0;i<length;i++){
            sb.append(2);
        }


        return sb.toString();
    }
}
